﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DisplayBoardInfo.Logger
{
    public static class Logger
    {
        private static Dictionary<DateTime, LogMessage> messages = new Dictionary<DateTime, LogMessage>();

        internal static Dictionary<DateTime, LogMessage> Messages
        {
            get { return Logger.messages; }
        }

        public delegate void LoggedHandler(object sender, LoggerEventArgs args);
        public static event LoggedHandler Logged;

        public static void Message(LogMessageType type, string message)
        {
            Message(new LogMessage(type, message));
        }

        public static void Message(LogMessage message)
        {
            try
            {
                messages.Add(DateTime.Now, message);
            }
            catch (Exception)
            { 
                //ignore
            }
            try
            {
                Logged(null, new LoggerEventArgs(message));
            }
            catch (NullReferenceException)
            { 
                //ignore
            }
        }
    }
}
